ast-grep: Utility Rule
from ast-grep: Rule Object
ast-grep: Utility Rule
ast-grepのruleを使いまわしたいときに使う
https://ast-grep.github.io/guide/rule-config/utility-rule.html
utils:内に書いたものは再利用可能になるらしい
code:yaml
# define util rules using utils field
utils:
# it accepts a string-keyed dictionary of rule object
is-literal: # rule-id
any: # actual rule object
- kind: 'false'
- kind: undefined
- kind: 'null'
- kind: 'true'
- kind: regex
- kind: number
- kind: string
rule:
any:
- matches: is-literal # reference the util!
- kind: array
has:
matches: is-literal # reference it again!
↑これはlocal utility rule
globalに定義したいなら
dirを作って、sgconfig.ymlで指定するなどの必要がある